package br.usp.ime.dojo.core.repositories.impl.memoria;

import java.util.HashMap;

import br.usp.ime.dojo.core.entities.Session;
import br.usp.ime.dojo.core.repositories.SessionRepository;

public class SessionRepositoryInMemory implements SessionRepository{
	private static SessionRepositoryInMemory instance = null;
	private HashMap<String,Session> sessions = new HashMap<String,Session>();
	

	public static SessionRepositoryInMemory getInstance() {
		if (instance == null) {
			instance = new SessionRepositoryInMemory();
		}
		return instance;
	}

	public Session get(String sessionId) {
		return sessions.get(sessionId);
	}

	public void add(Session session) {
		sessions.put(session.getId(),session);
	}

	public void clearAll() {
		sessions.clear();		
	}

	public String getNextSessionId() {
		return "" + sessions.size() + 1;
	}

}
